package com.quarkus.resource;


import com.quarkus.bean.Country;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

@Path("v2/name")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class CountryResource {

    private Map<String, Country> countries = new HashMap<>();

    public CountryResource() {
        countries.put("china", new Country("china", "Apple", "Winter fruit"));
        countries.put("us", new Country("us", "Pineapple", "Tropical fruit"));
    }

    @Path("{name}")
    @GET
    public Country list(@PathParam("name") String name) {
        return countries.get(name);
    }


    @Path("echo")
    @POST
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces(MediaType.TEXT_PLAIN)
    public String echo(String requestBody) throws Exception {
        System.err.println(requestBody);
        return requestBody;
    }

}